package com.zhouxiaoge.json;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
 * @author 周小哥  gqzmy@163.com 2022/8/14 10:20
 */

public class GsonUtils {

    /**
     * 创建Gson对象的方式
     */
    public static Gson gson() {
        return new Gson();
    }

    /**
     * 创建Gson对象的方式
     */
    public static Gson gsonBuilder() {
        GsonBuilder gsonBuilder = new GsonBuilder();
        // JSON格式化输出
        gsonBuilder.setPrettyPrinting();
        // 空值的序列化
        gsonBuilder.serializeNulls();
        gsonBuilder.registerTypeAdapterFactory(new NullString2EmptyAdapterFactory());
        gsonBuilder.registerTypeAdapter(Boolean.class, new BooleanSerializer());
        return gsonBuilder.create();
    }
}
